package com.freak.kotlinfitnessserver.activity

import android.os.Bundle
import android.text.TextUtils
import androidx.appcompat.app.AppCompatActivity
import androidx.viewpager.widget.ViewPager
import com.freak.kotlinfitnessserver.activity.adapter.SectionsPagerAdapter
import com.freak.kotlinfitnessserver.constant.DeviceConstant
import com.freak.kotlinfitnessserver.databinding.ActivityConfigBinding
import com.freak.kotlinfitnessserver.util.LogUtil
import com.freak.kotlinfitnessserver.util.ToastUtil
import com.google.android.material.tabs.TabLayout

class ConfigActivity : AppCompatActivity() {
    private lateinit var binding: ActivityConfigBinding
    private lateinit var deviceType: String
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityConfigBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.linearLayoutCompatConfigBack.setOnClickListener {
            finish()
        }
        intent ?: let {
            LogUtil.i(BleServerActivity.TAG, "intent is null")
            return
        }
        deviceType = intent.getStringExtra(DeviceConstant.deviceType) as String
        if (TextUtils.isEmpty(deviceType)) {
            ToastUtil.toastShort("设备类型错误")
            return
        }
        val sectionsPagerAdapter = SectionsPagerAdapter(this, supportFragmentManager, deviceType)
        val viewPager: ViewPager = binding.viewPager
        viewPager.adapter = sectionsPagerAdapter
        val tabs: TabLayout = binding.tabs
        viewPager.offscreenPageLimit = 4
        tabs.setupWithViewPager(viewPager)
    }
}